package com.bridge.bridge_wd.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bridge.bridge_wd.R;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

/**
 * @ClassName QianDaoAdapter
 * @Description TODO消息
 * @Author xushufeng
 * @CreateDate 2021/4/18 0018 10:57
 * @Version 1.0
 * @UpdateDate 2021/4/18 0018 10:57
 * @UpdateRemark 更新说明
 */
public class QianDaoAdapter extends RecyclerView.Adapter<QianDaoAdapter.BabyGoodsVH> {

    private Context mContext;
    private List<String> datas;
    private ItemClickListener mItemClickListener;
    String day_of_month;

    public QianDaoAdapter(Context mContext, List<String> datas, String day_of_month) {
        this.mContext = mContext;
        this.datas = datas;
        this.day_of_month = day_of_month;
    }

    @Override
    public BabyGoodsVH onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new BabyGoodsVH(LayoutInflater.from(mContext).inflate(R.layout.time_qiandao_item, viewGroup, false));
    }


    @Override
    public void onBindViewHolder(@NonNull BabyGoodsVH babyGoodsVH, int i) {
        babyGoodsVH.time_tv.setText(datas.get(i));
        if (day_of_month.equals(datas.get(i))) {
            babyGoodsVH.time_tv.setBackground(mContext.getResources().getDrawable(R.drawable.shape_yuan_red));
            babyGoodsVH.time_tv.setTextColor(mContext.getResources().getColor(R.color.white));
        }else{
            babyGoodsVH.time_tv.setBackground(mContext.getResources().getDrawable(R.drawable.shape_yuan_write));
            babyGoodsVH.time_tv.setTextColor(mContext.getResources().getColor(R.color.color_333333));
        }
        babyGoodsVH.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (mItemClickListener != null) {
                    mItemClickListener.onItemClick(v, i);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }

    public void addAll(List<String> data) {
        datas.addAll(data);
        notifyDataSetChanged();
    }

    public void clearAll() {
        datas.clear();
        notifyDataSetChanged();
    }

    public interface ItemClickListener {
        void onItemClick(View view, int i);
    }

    public void setOnItemClickListener(ItemClickListener itemClickListener) {
        this.mItemClickListener = itemClickListener;
    }

    static class BabyGoodsVH extends RecyclerView.ViewHolder {

        TextView time_tv;


        public BabyGoodsVH(@NonNull View itemView) {
            super(itemView);
            time_tv = itemView.findViewById(R.id.time_tv);

        }
    }
}

